﻿namespace MicroCloud.Authorization.Database
{
    #region "模块角色信息数据实体映射配置"
    /// <summary>
    /// 模块角色信息数据实体映射配置
    /// </summary>
    public class ModuleRoleConfiguration : EntityTypeConfigurationBase<ModuleRole, long>
    {
        #region "方法"
        #region "重写以实现实体类型各个属性的数据库配置"
        /// <summary>
        /// 重写以实现实体类型各个属性的数据库配置
        /// </summary>
        /// <param name="builder">实体类型创建器</param>
        public override void Configuration(EntityTypeBuilder<ModuleRole> builder)
        {
            //builder.HasIndex(m => new { m.ModuleId, m.RoleId }).HasDatabaseName("IDX_ModuleRole_ModuleRoleId").IsUnique();
            builder.HasIndex(m => new { m.ModuleId, m.RoleId }).SetIndex("ModuleRoleId", true);

            //builder.HasOne(mr => mr.Module).WithMany().HasForeignKey(m => m.ModuleId).HasConstraintName("FK_ModuleRole_ModuleId").IsRequired();
            //builder.HasOne(mr => mr.Role).WithMany().HasForeignKey(m => m.RoleId).HasConstraintName("FK_ModuleRole_RoleId").IsRequired();

            builder.HasOne(mr => mr.Module).WithMany().HasForeignKey(m => m.ModuleId).SetForeignKey("ModuleId");

            //builder.HasQueryFilter(o => o.Role.DeletedTime == null);

            ConfigurationAppend(builder);
        }
        #endregion

        #endregion

    }
    #endregion

}
